package com.nuit.cxl.ch2.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.nuit.cxl.ch2.mapper.UserMapper;
import com.nuit.cxl.ch2.service.StudentService;
import com.nuit.cxl.ch2.vo.Student;
import com.nuit.cxl.ch2.vo.StudentVO;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {

//    @Autowired
    @Resource
    UserMapper userMapper;

    @Override
    public Student getStudentById(int id) {
        Student student = userMapper.selectById(id);
        //过滤掉一些东西
        if(student.getAge() > 18){
            return new Student();
        }
        return student;
    }

    @Override
    public List<Student> getStudentsByAge(int age) {

//        QueryWrapper<Student> wrapper = new QueryWrapper<>();
        // WHERE `age` = #{age}"
        //    @Select("SELECT * FROM `user` WHERE `age` = #{age}")
//        wrapper.eq("age", age);
//        wrapper.ge("abc", age);

        LambdaQueryWrapper<Student> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Student::getAge, age);

        List<Student> students = userMapper.selectList(queryWrapper);

        return students;
    }


}
